<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  

  
  <title>姚毅的小笔记</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="姚毅的小笔记">
<meta property="og:url" content="http://vcomyaoyi.gitee.io/yaostaticblog/index.html">
<meta property="og:site_name" content="姚毅的小笔记">
<meta property="og:locale" content="zh">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="姚毅的小笔记">
  
    <link rel="alternate" href="/yaostaticblog/atom.xml" title="姚毅的小笔记" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/yaostaticblog/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/yaostaticblog/" id="logo">姚毅的小笔记</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/yaostaticblog/" id="subtitle">记录，学习，分享</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/yaostaticblog/">Home</a>
        
          <a class="main-nav-link" href="/yaostaticblog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/yaostaticblog/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://vcomyaoyi.gitee.io/yaostaticblog"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-java/java基础/java基础" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/yaostaticblog/2019/11/11/java/java基础/java基础/" class="article-date">
  <time datetime="2019-11-10T16:00:00.000Z" itemprop="datePublished">2019-11-11</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/yaostaticblog/categories/java/">java</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/yaostaticblog/2019/11/11/java/java基础/java基础/">java基础</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="java"><a href="#java" class="headerlink" title="java"></a>java</h1><h2 id="1、java基础"><a href="#1、java基础" class="headerlink" title="1、java基础"></a>1、java基础</h2><h3 id="1-1面向对象"><a href="#1-1面向对象" class="headerlink" title="1.1面向对象"></a>1.1面向对象</h3><p><strong>定义：</strong></p>
<ul>
<li><p>类：是对具有相同特征和行为的东西的统一描述和定义</p>
</li>
<li><p>属性：就是特征</p>
</li>
<li><p>方法：就是行为</p>
</li>
<li><p>对象：就是类的具体化，类是一个抽象的定义，对象是具体的实现</p>
</li>
</ul>
<p>例如：人类就是一个类，人类有四肢，有眼睛鼻子等，这些就是属性。人类可以打游戏，睡觉，吃饭，这些就是行为。</p>
<p><strong>代码中如何定义使用</strong></p>
<ol>
<li>类定义(<strong>类的第一个字母大写</strong>)</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Hero</span> </span>&#123; </span><br><span class="line">    String name; <span class="comment">//姓名</span></span><br><span class="line">    <span class="keyword">float</span> hp; <span class="comment">//血量 </span></span><br><span class="line">    <span class="keyword">float</span> armor; <span class="comment">//护甲 </span></span><br><span class="line">    <span class="keyword">int</span> moveSpeed; <span class="comment">//移动速度</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>定义方法（小驼峰命名）</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Hero</span> </span>&#123;</span><br><span class="line">    String name; <span class="comment">//姓名</span></span><br><span class="line">      </span><br><span class="line">    <span class="keyword">float</span> hp; <span class="comment">//血量</span></span><br><span class="line">      </span><br><span class="line">    <span class="keyword">float</span> armor; <span class="comment">//护甲</span></span><br><span class="line">      </span><br><span class="line">    <span class="keyword">int</span> moveSpeed; <span class="comment">//移动速度</span></span><br><span class="line"> </span><br><span class="line">    <span class="comment">//坑队友，没有返回值的方法</span></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">keng</span><span class="params">()</span></span>&#123;</span><br><span class="line">        System.out.println(<span class="string">"坑队友！"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//获取护甲值,有返回值的方法</span></span><br><span class="line">    <span class="function"><span class="keyword">float</span> <span class="title">getArmor</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> armor</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//增加移动速度，有参数</span></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">addSpeed</span><span class="params">(<span class="keyword">int</span> speed)</span></span>&#123;</span><br><span class="line">        <span class="comment">//在原来的基础上增加移动速度</span></span><br><span class="line">        moveSpeed = moveSpeed + speed;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>对象创建</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Hero</span> </span>&#123;</span><br><span class="line">    String name; <span class="comment">//姓名 </span></span><br><span class="line">    <span class="keyword">float</span> hp; <span class="comment">//血量 </span></span><br><span class="line">    <span class="keyword">float</span> armor; <span class="comment">//护甲</span></span><br><span class="line">    <span class="keyword">int</span> moveSpeed; <span class="comment">//移动速度</span></span><br><span class="line">     </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        Hero garen =  <span class="keyword">new</span> Hero();</span><br><span class="line">        garen.name = <span class="string">"盖伦"</span>;</span><br><span class="line">        garen.hp = <span class="number">616.28f</span>;</span><br><span class="line">        garen.armor = <span class="number">27.536f</span>;</span><br><span class="line">        garen.moveSpeed = <span class="number">350</span>;</span><br><span class="line">         </span><br><span class="line">        Hero teemo =  <span class="keyword">new</span> Hero();</span><br><span class="line">        teemo.name = <span class="string">"提莫"</span>;</span><br><span class="line">        teemo.hp = <span class="number">383f</span>;</span><br><span class="line">        teemo.armor = <span class="number">14f</span>;</span><br><span class="line">        teemo.moveSpeed = <span class="number">330</span>;</span><br><span class="line">    &#125;  </span><br><span class="line">     </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="1-2变量"><a href="#1-2变量" class="headerlink" title="1.2变量"></a>1.2变量</h3><p>定义：就是用来命名一个数据的标识符</p>
<h4 id="1-2-1基本变量类型"><a href="#1-2-1基本变量类型" class="headerlink" title="1.2.1基本变量类型"></a>1.2.1基本变量类型</h4><p>基本变量类型分别为：</p>
<p><em>整型（4种）、字符型（1种）、浮点型（2种）</em></p>
<ul>
<li>整型</li>
</ul>
<blockquote>
<p>整型变量用于存放整数<br>byte<br>short<br>int<br>long<br>区别在于不同类型的整型，最大值，最小值不一样<br>如果试图给byte类型的变量赋予超出其范围的值，就会产生编译错误，这个时候就需要进行类型转换。</p>
</blockquote>
<p><img src=".%5Cimg%5C513.png" alt="整型数据类型"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span></span>&#123;</span><br><span class="line">    </span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>&#123;</span><br><span class="line">      <span class="keyword">byte</span> b = <span class="number">1</span>;</span><br><span class="line">      <span class="keyword">short</span> s = <span class="number">200</span>;</span><br><span class="line">      <span class="keyword">int</span> i = <span class="number">300</span>;</span><br><span class="line">      <span class="keyword">long</span> l = <span class="number">400</span>; </span><br><span class="line">      <span class="comment">/*如果试图给byte类型的变量赋予超出其范围的值，就会产生编译错误*/</span></span><br><span class="line">      <span class="keyword">byte</span> b2 = <span class="number">200</span>;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>字符型</li>
</ul>
<blockquote>
<p>char类型用于存放一个字符，值用单引号’表示 (双引号表示字符串)<br>其长度和short一样，也是16位的<br><strong>只能存放一个字符</strong>，超过一个字符就会产生编译错误 </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span></span>&#123; </span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>&#123;</span><br><span class="line">      <span class="keyword">char</span> c = <span class="string">'中'</span>;</span><br><span class="line">      <span class="comment">//char 只能存放一个字符，超过一个字符就会产生编译错误</span></span><br><span class="line">      <span class="keyword">char</span> c2 = <span class="string">'中国'</span>; <span class="comment">//报错</span></span><br><span class="line">      <span class="keyword">char</span> c3 = <span class="string">'ab'</span>; <span class="comment">//报错</span></span><br><span class="line"> </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>浮点型</li>
</ul>
<blockquote>
<p>浮点数类型有两种<br>float 长度为32位<br>double 长度为64位<br><strong>注意： 默认的小数值是double类型的</strong><br>所以 float f = 54.321会出现编译错误，因为54.321的默认类型是 double，其类型 长度为64，超过了float的长度32<br>在数字后面<strong>加一个字母f</strong>，直接把该数字声明成float类型<br>float f2 = 54.321<strong>f</strong>,<br>这样就不会出错了 </p>
</blockquote>
<p><img src=".%5Cimg%5C515.png" alt="浮点型数据类型"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span></span>&#123;</span><br><span class="line">     </span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>&#123;</span><br><span class="line">      <span class="keyword">double</span> d = <span class="number">123.45</span>;        </span><br><span class="line">      <span class="comment">//该行会出现编译错误，因为54.321是double型的</span></span><br><span class="line">      <span class="keyword">float</span> f = <span class="number">54.321</span>;</span><br><span class="line">        </span><br><span class="line">      <span class="keyword">float</span> f2 = <span class="number">54.321f</span>;</span><br><span class="line">        </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>布尔型</li>
</ul>
<blockquote>
<p>布尔型用于表示真假</p>
<p>其长度为1</p>
<blockquote>
<p>boolean b1 = true;</p>
<p>boolean b2 = true;</p>
</blockquote>
<p>分别代表真假虽然布尔型真正存放的数据是0(false) 1(true)但是，不能直接使用0 1 进行赋值</p>
</blockquote>
<p><img src=".%5Cimg%5C516.png" alt="布尔类型"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">boolean</span> b1 = <span class="keyword">true</span>;</span><br><span class="line">        <span class="keyword">boolean</span> b2 = <span class="keyword">false</span>;</span><br><span class="line"> </span><br><span class="line">        <span class="comment">// 虽然布尔型真正存放的数据是0(false) 1(true)</span></span><br><span class="line">        <span class="comment">// 但是，不能直接使用0 1 进行赋值</span></span><br><span class="line">        <span class="keyword">boolean</span> b3 = <span class="number">1</span>;</span><br><span class="line"> </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>String类型</li>
</ul>
<blockquote>
<p> String类型其实<strong>并不是基本类型</strong>，但是它是如此广泛的被使用，常常被误以为是一种基本类型。<br>String类型是Immutable的，一旦创建就不能够被改变，更多的关于String的学习，<a href="https://how2j.cn/k/number-string/number-string-string/324.html#step700" target="_blank" rel="noopener">请参考String</a> </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        String str = <span class="string">"Hello Java"</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-2-2字面值"><a href="#1-2-2字面值" class="headerlink" title="1.2.2字面值"></a>1.2.2字面值</h4><blockquote>
<p> 创建一个Hero对象会用到new关键字，但是给一个基本类型变量赋值却不是用new. 因为基本类型是Java语言里的一种内置的特殊数据类型，并不是某个类的对象。<br>给基本类型的变量赋值的方式叫做 <strong>字面值</strong>，如下所例：  </p>
<blockquote>
<p>float hp = 313f; </p>
<p>int armor = 24;</p>
</blockquote>
</blockquote>
<ul>
<li>整数字面值</li>
</ul>
<blockquote>
<p> 当以l或者L结尾的时候，一个整数字面值是long类型，否则就是int类型。 建议使用<strong>大写的L</strong>而非小写的l，因为容易和1混淆。<br>byte,short,int和long的值都可以通过int类型的字面值来创建。整数的字面值可以用如下四种进制来表示：<br>十进制: 基 10, 包含从0-9的数字，<strong>平常用的就是这种</strong><br>十六进制: 基 16, 包含从0-9的数字，和从A-F的字母。<br>八进制: 基 8, 包含从0-7的数字<br>二进制: 基 2, 包含0和1。（从 JAVA7开始就可以创建 二进制的字面值了） </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">long</span> val = <span class="number">26L</span>; <span class="comment">//以L结尾的字面值表示long型</span></span><br><span class="line">        <span class="keyword">int</span> decVal = <span class="number">26</span>; <span class="comment">//默认就是int型</span></span><br><span class="line">        <span class="keyword">int</span> hexVal = <span class="number">0x1a</span>; <span class="comment">//16进制</span></span><br><span class="line">        <span class="keyword">int</span> oxVal = <span class="number">032</span>; <span class="comment">//8进制</span></span><br><span class="line">        <span class="keyword">int</span> binVal = <span class="number">0b11010</span>; <span class="comment">//2进制</span></span><br><span class="line">        System.out.println(oxVal);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>浮点数字面值</li>
</ul>
<blockquote>
<p> 当以f或者F结尾的时候，就表示一个float类型的浮点数，否则就是double类型（以d或者D结尾，写不写都可以）。<br>浮点数还可以用E或者e表示（科学计数法）<br>e2表示10的二次方，即100<br>1.234e2 = 1.234x100 </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">float</span> f1 = <span class="number">123.4F</span>;<span class="comment">// 以F结尾的字面值表示float类型</span></span><br><span class="line">        <span class="keyword">double</span> d1 = <span class="number">123.4</span>;<span class="comment">// 默认就是double类型</span></span><br><span class="line">        <span class="keyword">double</span> d2 = <span class="number">1.234e2</span>;<span class="comment">// 科学计数法表示double</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>字符字符串字面值</li>
</ul>
<blockquote>
<p> 字符的字面值放在单引号中</p>
<p><strong>字符串</strong>的字面值放在双引号中</p>
<p>需要注意的是，\表示转义，比如需要表示制表符，回车换行，双引号等就需要用 \t \r \n &quot; 的方式进行 </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        String name = <span class="string">"盖伦"</span>;</span><br><span class="line">        <span class="keyword">char</span> a= <span class="string">'c'</span>;</span><br><span class="line"> </span><br><span class="line">        <span class="comment">//以下是转义字符</span></span><br><span class="line">        <span class="keyword">char</span> tab = <span class="string">'\t'</span>; <span class="comment">//制表符</span></span><br><span class="line">        <span class="keyword">char</span> carriageReturn = <span class="string">'\r'</span>; <span class="comment">//回车</span></span><br><span class="line">        <span class="keyword">char</span> newLine = <span class="string">'\n'</span>; <span class="comment">//换行</span></span><br><span class="line">        <span class="keyword">char</span> doubleQuote = <span class="string">'\"'</span>; <span class="comment">//双引号</span></span><br><span class="line">        <span class="keyword">char</span> singleQuote = <span class="string">'\''</span>; <span class="comment">//单引号</span></span><br><span class="line">        <span class="keyword">char</span> backslash = <span class="string">'\\'</span>; <span class="comment">//反斜杠</span></span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-2-3类型传唤"><a href="#1-2-3类型传唤" class="headerlink" title="1.2.3类型传唤"></a>1.2.3类型传唤</h4><blockquote>
<p> 转换规则如图所示<br><strong>精度高</strong>的数据类型就像<strong>容量大</strong>的杯子，可以<strong>放更大</strong>的数据<br><strong>精度低</strong>的数据类型就像<strong>容量小</strong>的杯子，只能<strong>放更小</strong>的数据<br>小杯子往大杯子里倒东西，大杯子<strong>怎么都放得下</strong><br>大杯子往小杯子里倒东西，<strong>有的时候放的下</strong>，<strong>有的时候就会有溢出</strong><br>需要注意的一点是<br>虽然short和char都是16位的，长度是一样的<br>但是彼此之间，依然需要进行强制转换 </p>
</blockquote>
<p><img src=".%5Cimg%5C519.png" alt="数据类型转换"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">char</span> c = <span class="string">'A'</span>;</span><br><span class="line">        <span class="keyword">short</span> s = <span class="number">80</span>;</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//虽然short和char都是16位的，长度是一样的</span></span><br><span class="line">        <span class="comment">//但是彼此之间，依然需要进行强制转换</span></span><br><span class="line">        c = (<span class="keyword">char</span>) s;</span><br><span class="line">        <span class="comment">//直接进行转换，会出现编译错误</span></span><br><span class="line">        s = c;</span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>低精度向高精度转换</li>
</ul>
<blockquote>
<p>long l = 50;</p>
<p>int i = 50;</p>
</blockquote>
<p>l是long类型的，其类型长度是64位。i是int类型的，其类型长度是32位。所以l的精度比i的精度高，l=i；把i的值赋给l，首先l和i彼此的类型是不一样的，那么能否转换就取决于彼此的精度。这个例子，是低精度向高精度转换 是可以正常转换的，换句话说，int比较小，要放进比较大的long杯子里，随便怎么放都可以。</p>
<p><img src=".%5Cimg%5C517.png" alt="int转long图解"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">  </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">  </span><br><span class="line">        <span class="keyword">long</span> l = <span class="number">50</span>;</span><br><span class="line">        <span class="keyword">int</span> i = <span class="number">50</span>;</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//int比较小，要放进比较大的long,随便怎么样，都放的进去</span></span><br><span class="line">        l = i;</span><br><span class="line">          </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>高精度向低精度转换</li>
</ul>
<blockquote>
<p>byte b = 5;</p>
<p>int i1 = 10;</p>
<p>int i2 = 300;</p>
<p>b = i1;</p>
<p>b=i2;</p>
</blockquote>
<blockquote>
<p> b的类型是byte,其长度是8，<strong>最大只能放127</strong><br>i1 的类型是int, 其长度是32,最大，反正就是很大了，超过127<br>所以， 把int类型的数据转成为byte类型的数据，<strong>是有风险的</strong><br><strong>有的时候是可以转换的</strong>，比如 b = i1 (i1=10);<br><strong>有的时候不可以转换</strong> 比如 b= i2 (i2=300) 因为放不下了<br>编译器就会提示错误<br>这个时候就只能采用<strong>强制转换</strong>，强制转换的意思就是，转是可以转的，但是不对转换之后的值负责。 风险自担，后果自负 </p>
</blockquote>
<p><img src=".%5Cimg%5C518.png" alt="int转成byte"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">  </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">  </span><br><span class="line">        <span class="keyword">byte</span> b = <span class="number">5</span>;</span><br><span class="line">        <span class="keyword">int</span> i1 = <span class="number">10</span>;</span><br><span class="line">        <span class="keyword">int</span> i2 = <span class="number">300</span>;</span><br><span class="line">          </span><br><span class="line">        b = (<span class="keyword">byte</span>) i1;</span><br><span class="line">        <span class="comment">//因为i1的值是在byte范围之内，所以即便进行强制转换</span></span><br><span class="line">        <span class="comment">//最后得到的值，也是10</span></span><br><span class="line">        System.out.println(b);</span><br><span class="line">          </span><br><span class="line">        <span class="comment">//因为i2的值是在byte范围之外，所以就会按照byte的长度进行截取</span></span><br><span class="line">        <span class="comment">//i2的值是300，其对应的二进制数是 100101100</span></span><br><span class="line">        <span class="comment">//按照byte的长度8位进行截取后，其值为 00101100 即44</span></span><br><span class="line">        b =(<span class="keyword">byte</span>) i2;</span><br><span class="line">        System.out.println(b);</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//查看一个整数对应的二进制的方法：</span></span><br><span class="line">        System.out.println(Integer.toBinaryString(i2));</span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-2-4命名规则"><a href="#1-2-4命名规则" class="headerlink" title="1.2.4命名规则"></a>1.2.4命名规则</h4><ul>
<li>命名规则</li>
</ul>
<blockquote>
<p>变量命名只能使用<strong>字母 数字 $ _</strong><br>变量第一个字符 只能使用 字母 $ _<br>变量第一个字符 不能使用数字<br>注：_ 是下划线，不是-减号或者—— 破折号 </p>
</blockquote>
<h4 id="1-2-5作用域"><a href="#1-2-5作用域" class="headerlink" title="1.2.5作用域"></a>1.2.5作用域</h4><blockquote>
<p> 变量处于不同的位置，有不同的名称 </p>
<p>分别是<br>字段，属性<br>参数<br>局部变量 </p>
<p>不同名称的变量，其作用域是不一样的 </p>
</blockquote>
<ul>
<li>字段，属性，Field</li>
</ul>
<blockquote>
<p> 当一个变量被声明在类下面<br>变量就叫做<strong>字段</strong> 或者<strong>属性</strong>、<strong>成员变量</strong>、<strong>Field</strong><br>比如变量i,就是一个属性。<br>那么从第2行这个变量声明的位置开始，整个类都可以访问得到<br>所以其作用域就是从其声明的位置开始的整个类 </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> i = <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">int</span> j = i;  <span class="comment">//其他的属性可以访问i</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">method1</span><span class="params">()</span></span>&#123;</span><br><span class="line">        System.out.println(i); <span class="comment">//方法1里可以访问i</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">method2</span><span class="params">()</span></span>&#123;</span><br><span class="line">        System.out.println(i); <span class="comment">//方法2里可以访问i</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>参数</li>
</ul>
<blockquote>
<p> 如果一个变量，是声明在一个方法上的，就叫做<strong>参数</strong><br>参数的作用域即为该方法内的所有代码<br>其他方法不能访问该参数<br>类里面也不能访问该参数 </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">method1</span><span class="params">(<span class="keyword">int</span> i)</span></span>&#123; <span class="comment">//参数i的作用域即方法method1</span></span><br><span class="line">        System.out.println(i);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">method2</span><span class="params">()</span></span>&#123;</span><br><span class="line"> </span><br><span class="line">        System.out.println(i); <span class="comment">//method2 不能访问参数i</span></span><br><span class="line">    &#125;</span><br><span class="line">     </span><br><span class="line">    <span class="keyword">int</span> j = i;  <span class="comment">//类里面也不能访问参数i</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>局部变量</li>
</ul>
<blockquote>
<p> 声明在方法内的变量，叫做局部变量<br>其作用域在声明开始的位置，到其所处于的块结束位置 </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">method1</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> i  = <span class="number">5</span>;  <span class="comment">//其作用范围是从声明的第4行，到其所处于的块结束12行位置</span></span><br><span class="line">        System.out.println(i);</span><br><span class="line">        &#123;            <span class="comment">//子块</span></span><br><span class="line">            System.out.println(i); <span class="comment">//可以访问i</span></span><br><span class="line">            <span class="keyword">int</span> j = <span class="number">6</span>;</span><br><span class="line">            System.out.println(j); <span class="comment">//可以访问j</span></span><br><span class="line">        &#125;</span><br><span class="line">        System.out.println(j); <span class="comment">//不能访问j,因为其作用域到第10行就结束了</span></span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-2-6-final"><a href="#1-2-6-final" class="headerlink" title="1.2.6 final"></a>1.2.6 final</h4><blockquote>
<p> final 修饰一个变量，有很多种说法，比如不能改变等等<br>准确的描述是 当一个变量被final修饰的时候，该变量<strong>只有一次赋值的机会</strong> </p>
</blockquote>
<h4 id="1-2-7-表达式"><a href="#1-2-7-表达式" class="headerlink" title="1.2.7 表达式"></a>1.2.7 表达式</h4><blockquote>
<p> 以;结尾的一段代码，即为一个表达式 </p>
</blockquote>
<h4 id="1-2-8-块"><a href="#1-2-8-块" class="headerlink" title="1.2.8 块"></a>1.2.8 块</h4><blockquote>
<p>从{ 开始 到对应的} 结束，即一个块 </p>
</blockquote>
<h3 id="1-3操作符"><a href="#1-3操作符" class="headerlink" title="1.3操作符"></a>1.3操作符</h3><h4 id="1-3-1算术操作符"><a href="#1-3-1算术操作符" class="headerlink" title="1.3.1算术操作符"></a>1.3.1算术操作符</h4><p>基本的有：</p>
<blockquote>
<p> + - * / % </p>
</blockquote>
<p>自增、自减</p>
<blockquote>
<p>++ –</p>
</blockquote>
<ul>
<li>基本算数运算，加减乘除</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> i = <span class="number">10</span>;</span><br><span class="line">        <span class="keyword">int</span> j = <span class="number">5</span>;</span><br><span class="line">        <span class="keyword">int</span> a = i+j;</span><br><span class="line">        <span class="keyword">int</span> b = i - j;</span><br><span class="line">        <span class="keyword">int</span> c = i*j;</span><br><span class="line">        <span class="keyword">int</span> d = i /j;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>任意运算单元的长度超过int</li>
</ul>
<p>如果任何运算单元长度超过int，那么运算结果就按最长的长度计算</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">int</span> a = <span class="number">5</span>;</span><br><span class="line">        <span class="keyword">long</span> b = <span class="number">6</span>;</span><br><span class="line">        <span class="keyword">int</span> c = (<span class="keyword">int</span>) (a+b); <span class="comment">//a+b的运算结果是long型，所以要进行强制转换</span></span><br><span class="line">        <span class="keyword">long</span> d = a+b;</span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>%取模，又叫取余</li>
<li>自增、自减操作符置前和置后的区别</li>
</ul>
<blockquote>
<p>i++; <strong>先取值，再运算</strong><br>++i; <strong>先运算，再取值</strong> </p>
</blockquote>
<h4 id="1-3-2关系操作符"><a href="#1-3-2关系操作符" class="headerlink" title="1.3.2关系操作符"></a>1.3.2关系操作符</h4><blockquote>
<p> &gt; 大于<br>&gt;= 大于或等于<br>&lt; 小于<br>&lt;= 小于或等于<br>== 是否相等<br>!= 是否不等 </p>
</blockquote>
<h4 id="1-3-3逻辑操作符"><a href="#1-3-3逻辑操作符" class="headerlink" title="1.3.3逻辑操作符"></a>1.3.3逻辑操作符</h4><table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
<th>代码示例</th>
</tr>
</thead>
<tbody><tr>
<td>&amp;    &amp;&amp;</td>
<td>长路与 和 短路与</td>
<td><a href="#yu">示例代码</a></td>
</tr>
<tr>
<td>|    ||</td>
<td>长路或 和 短路或</td>
<td><a href="#huo">示例代码</a></td>
</tr>
<tr>
<td>!</td>
<td>取反</td>
<td><a href="#fei">示例代码</a></td>
</tr>
<tr>
<td>^</td>
<td>异或^</td>
<td><a href="#yihuo">示例代码</a></td>
</tr>
</tbody></table>
<p><span id="yu">&amp; &amp;&amp;</span></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="comment">//长路与  无论第一个表达式的值是true或者false,第二个的值，都会被运算</span></span><br><span class="line">        <span class="keyword">int</span> i = <span class="number">2</span>;</span><br><span class="line">        System.out.println( i== <span class="number">1</span> &amp; i++ ==<span class="number">2</span>  ); <span class="comment">//无论如何i++都会被执行，所以i的值变成了3</span></span><br><span class="line">        System.out.println(i);</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//短路与 只要第一个表达式的值是false的，第二个表达式的值，就不需要进行运算了</span></span><br><span class="line">        <span class="keyword">int</span> j = <span class="number">2</span>;</span><br><span class="line">        System.out.println( j== <span class="number">1</span> &amp;&amp; j++ ==<span class="number">2</span>  );  <span class="comment">//因为j==1返回false,所以右边的j++就没有执行了，所以j的值，还是2</span></span><br><span class="line">        System.out.println(j);     </span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><span id="huo">| ||</span></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="comment">//长路或  无论第一个表达式的值是true或者false,第二个的值，都会被运算</span></span><br><span class="line">        <span class="keyword">int</span> i = <span class="number">2</span>;</span><br><span class="line">        System.out.println( i== <span class="number">1</span> | i++ ==<span class="number">2</span>  ); <span class="comment">//无论如何i++都会被执行，所以i的值变成了3</span></span><br><span class="line">        System.out.println(i);</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//短路或 只要第一个表达式的值是true的，第二个表达式的值，就不需要进行运算了</span></span><br><span class="line">        <span class="keyword">int</span> j = <span class="number">2</span>;</span><br><span class="line">        System.out.println( j== <span class="number">2</span> || j++ ==<span class="number">2</span>  );  <span class="comment">//因为j==2返回true,所以右边的j++就没有执行了，所以j的值，还是2</span></span><br><span class="line">        System.out.println(j);     </span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><span id="fei">!</span></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">boolean</span> b = <span class="keyword">true</span>;</span><br><span class="line">         </span><br><span class="line">        System.out.println(b); <span class="comment">//输出true</span></span><br><span class="line">        System.out.println(!b);<span class="comment">//输出false</span></span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><span id="yihuo">^</span></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">boolean</span> a = <span class="keyword">true</span>;</span><br><span class="line">        <span class="keyword">boolean</span> b = <span class="keyword">false</span>;</span><br><span class="line">         </span><br><span class="line">        System.out.println(a^b); <span class="comment">//不同返回真</span></span><br><span class="line">        System.out.println(a^!b); <span class="comment">//相同返回假</span></span><br><span class="line"> </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-3-4位操作符"><a href="#1-3-4位操作符" class="headerlink" title="1.3.4位操作符"></a>1.3.4位操作符</h4><h4 id="1-3-5赋值操作符"><a href="#1-3-5赋值操作符" class="headerlink" title="1.3.5赋值操作符"></a>1.3.5赋值操作符</h4><h4 id="1-3-6三元操作符"><a href="#1-3-6三元操作符" class="headerlink" title="1.3.6三元操作符"></a>1.3.6三元操作符</h4><blockquote>
<p>表达式?值1:值2<br>如果表达式为真 返回值1<br>如果表达式为假 返回值2 </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">int</span> i = <span class="number">5</span>;</span><br><span class="line">        <span class="keyword">int</span> j = <span class="number">6</span>;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">int</span> k = i &lt; j ? <span class="number">99</span> : <span class="number">88</span>;</span><br><span class="line"> </span><br><span class="line">        <span class="comment">// 相当于</span></span><br><span class="line">        <span class="keyword">if</span> (i &lt; j) &#123;</span><br><span class="line">            k = <span class="number">99</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            k = <span class="number">88</span>;</span><br><span class="line">        &#125;</span><br><span class="line"> </span><br><span class="line">        System.out.println(k);</span><br><span class="line"> </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-3-7Scanner"><a href="#1-3-7Scanner" class="headerlink" title="1.3.7Scanner"></a>1.3.7Scanner</h4><blockquote>
<p> import java.util.Scanner; </p>
<p> <code>Scanner s = ``new</code> <code>Scanner(System.in);</code> </p>
<p> <code>int</code> <code>a = s.nextInt();</code> </p>
<p> <code>float</code> <code>a = s.nextFloat();</code> </p>
<p> String a = s.nextLine(); </p>
</blockquote>
<h3 id="1-4流程控制"><a href="#1-4流程控制" class="headerlink" title="1.4流程控制"></a>1.4流程控制</h3><h4 id="1-4-1if"><a href="#1-4-1if" class="headerlink" title="1.4.1if"></a>1.4.1if</h4><ul>
<li>if</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(表达式<span class="number">1</span>)&#123;</span><br><span class="line">  表达式<span class="number">2</span>；</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>多表达式与一个表达式</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">         </span><br><span class="line">        <span class="keyword">boolean</span> b = <span class="keyword">false</span>;</span><br><span class="line">        <span class="comment">//如果有多个表达式，必须用大括弧包括起来</span></span><br><span class="line">        <span class="keyword">if</span>(b)&#123;</span><br><span class="line">            System.out.println(<span class="string">"yes1"</span>);</span><br><span class="line">            System.out.println(<span class="string">"yes2"</span>);</span><br><span class="line">            System.out.println(<span class="string">"yes3"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//否则表达式2 3 无论b是否为true都会执行</span></span><br><span class="line">         </span><br><span class="line">        <span class="keyword">if</span>(b)</span><br><span class="line">            System.out.println(<span class="string">"yes1"</span>);</span><br><span class="line">            System.out.println(<span class="string">"yes2"</span>);</span><br><span class="line">            System.out.println(<span class="string">"yes3"</span>);</span><br><span class="line">             </span><br><span class="line">        <span class="comment">//如果只有一个表达式可以不用写括弧，看上去会简约一些</span></span><br><span class="line">        <span class="keyword">if</span>(b)&#123;</span><br><span class="line">            System.out.println(<span class="string">"yes1"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">         </span><br><span class="line">        <span class="keyword">if</span>(b)</span><br><span class="line">            System.out.println(<span class="string">"yes1"</span>);</span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>if使用过程中可能遇到的坑</li>
</ul>
<blockquote>
<p> 在第6行，if后面有一个分号; 而<a href="https://how2j.cn/k/variable/variable-express/277.html#step557" target="_blank" rel="noopener">分号也是一个完整的表达式</a><br>如果b为true，会执行这个分号，然后打印yes<br>如果b为false，不会执行这个分号，然后打印yes<br>这样，看上去无论如何都会打印yes </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">boolean</span> b = <span class="keyword">false</span>;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">if</span> (b);</span><br><span class="line">            System.out.println(<span class="string">"yes"</span>);</span><br><span class="line"> </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>if else</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">boolean</span> b = <span class="keyword">false</span>;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">if</span> (b)</span><br><span class="line">            System.out.println(<span class="string">"yes"</span>);</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">            System.out.println(<span class="string">"no"</span>);</span><br><span class="line"> </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>else if</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">        <span class="comment">//如果只使用 if,会执行4次判断</span></span><br><span class="line">        <span class="keyword">int</span> i = <span class="number">2</span>;</span><br><span class="line">        <span class="keyword">if</span> (i==<span class="number">1</span>)</span><br><span class="line">            System.out.println(<span class="number">1</span>);</span><br><span class="line">        <span class="keyword">if</span> (i==<span class="number">2</span>)</span><br><span class="line">            System.out.println(<span class="number">2</span>);</span><br><span class="line">        <span class="keyword">if</span> (i==<span class="number">3</span>)</span><br><span class="line">            System.out.println(<span class="number">3</span>);</span><br><span class="line">        <span class="keyword">if</span> (i==<span class="number">4</span>)</span><br><span class="line">            System.out.println(<span class="number">4</span>);</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//如果使用else if, 一旦在18行，判断成立， 20行和22行的判断就不会执行了，节约了运算资源</span></span><br><span class="line">        <span class="keyword">if</span> (i==<span class="number">1</span>)</span><br><span class="line">            System.out.println(<span class="number">1</span>);</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (i==<span class="number">2</span>)</span><br><span class="line">            System.out.println(<span class="number">2</span>);</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (i==<span class="number">3</span>)</span><br><span class="line">            System.out.println(<span class="number">3</span>);</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (i==<span class="number">4</span>)</span><br><span class="line">            System.out.println(<span class="number">4</span>);     </span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-4-2switch"><a href="#1-4-2switch" class="headerlink" title="1.4.2switch"></a>1.4.2switch</h4><ul>
<li>switch</li>
</ul>
<blockquote>
<p> switch可以使用byte,short,int,char,String,enum</p>
<p><strong>注:</strong> 每个表达式结束，都应该有一个break;<br><strong>注:</strong> String在Java1.7之前是不支持的, Java从1.7开始支持switch用String的，编译后是把String转化为hash值，其实还是整数<br><strong>注:</strong> enum是枚举类型，在<a href="https://how2j.cn/k/class-object/class-object-enum/678.html" target="_blank" rel="noopener">枚举</a>章节有详细讲解 </p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//如果使用if else</span></span><br><span class="line">        <span class="keyword">int</span> day = <span class="number">5</span>;</span><br><span class="line">        <span class="keyword">if</span> (day==<span class="number">1</span>)</span><br><span class="line">            System.out.println(<span class="string">"星期一"</span>);</span><br><span class="line">              </span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (day==<span class="number">2</span>)</span><br><span class="line">            System.out.println(<span class="string">"星期二"</span>);</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (day==<span class="number">3</span>)</span><br><span class="line">            System.out.println(<span class="string">"星期三"</span>);</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (day==<span class="number">4</span>)</span><br><span class="line">            System.out.println(<span class="string">"星期四"</span>);</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (day==<span class="number">5</span>)</span><br><span class="line">            System.out.println(<span class="string">"星期五"</span>);</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (day==<span class="number">6</span>)</span><br><span class="line">            System.out.println(<span class="string">"星期六"</span>);</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (day==<span class="number">7</span>)</span><br><span class="line">            System.out.println(<span class="string">"星期天"</span>);</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">            System.out.println(<span class="string">"这个是什么鬼？"</span>);</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//如果使用switch</span></span><br><span class="line">        <span class="keyword">switch</span>(day)&#123;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line">                System.out.println(<span class="string">"星期一"</span>);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line">                System.out.println(<span class="string">"星期二"</span>);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line">                System.out.println(<span class="string">"星期三"</span>);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">4</span>:</span><br><span class="line">                System.out.println(<span class="string">"星期四"</span>);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">5</span>:</span><br><span class="line">                System.out.println(<span class="string">"星期五"</span>);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">6</span>:</span><br><span class="line">                System.out.println(<span class="string">"星期六"</span>);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="number">7</span>:</span><br><span class="line">                System.out.println(<span class="string">"星期天"</span>);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">default</span>:</span><br><span class="line">                System.out.println(<span class="string">"这个是什么鬼？"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-4-3-while和do-while"><a href="#1-4-3-while和do-while" class="headerlink" title="1.4.3 while和do while"></a>1.4.3 while和do while</h4><h4 id="1-4-4for"><a href="#1-4-4for" class="headerlink" title="1.4.4for"></a>1.4.4for</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">           </span><br><span class="line">        <span class="comment">//使用while打印0到4    </span></span><br><span class="line">        <span class="keyword">int</span> i = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">while</span>(i&lt;<span class="number">5</span>)&#123;</span><br><span class="line">            System.out.println(<span class="string">"while循环输出的"</span>+i);</span><br><span class="line">            i++;</span><br><span class="line">        &#125;</span><br><span class="line">          </span><br><span class="line">        <span class="comment">//使用for打印0到4    </span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; <span class="number">5</span>; j++) &#123;</span><br><span class="line">            System.out.println(<span class="string">"for  循环输出的"</span>+j);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-4-5continue"><a href="#1-4-5continue" class="headerlink" title="1.4.5continue"></a>1.4.5continue</h4><h4 id="1-4-6break"><a href="#1-4-6break" class="headerlink" title="1.4.6break"></a>1.4.6break</h4><h4 id="1-4-7结束外部循环"><a href="#1-4-7结束外部循环" class="headerlink" title="1.4.7结束外部循环"></a>1.4.7结束外部循环</h4><ul>
<li>结束当前循环</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">          </span><br><span class="line">        <span class="comment">//打印单数    </span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">10</span>; i++) &#123;</span><br><span class="line">             </span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; <span class="number">10</span>; j++) &#123;</span><br><span class="line">                System.out.println(i+<span class="string">":"</span>+j);</span><br><span class="line">                <span class="keyword">if</span>(<span class="number">0</span>==j%<span class="number">2</span>) </span><br><span class="line">                    <span class="keyword">break</span>; <span class="comment">//如果是双数，结束当前循环</span></span><br><span class="line">            &#125;</span><br><span class="line">             </span><br><span class="line">        &#125;</span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>使用boolean变量结束外部循环</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">boolean</span> breakout = <span class="keyword">false</span>; <span class="comment">//是否终止外部循环的标记</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">10</span>; i++) &#123;</span><br><span class="line"> </span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; <span class="number">10</span>; j++) &#123;</span><br><span class="line">                System.out.println(i + <span class="string">":"</span> + j);</span><br><span class="line">                <span class="keyword">if</span> (<span class="number">0</span> == j % <span class="number">2</span>) &#123;</span><br><span class="line">                    breakout = <span class="keyword">true</span>; <span class="comment">//终止外部循环的标记设置为true</span></span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (breakout) <span class="comment">//判断是否终止外部循环</span></span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line"> </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>使用标签结束外部循环</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">          </span><br><span class="line">        <span class="comment">//打印单数    </span></span><br><span class="line">        outloop: <span class="comment">//outloop这个标示是可以自定义的比如outloop1,ol2,out5</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">10</span>; i++) &#123;</span><br><span class="line">             </span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; <span class="number">10</span>; j++) &#123;</span><br><span class="line">                System.out.println(i+<span class="string">":"</span>+j);</span><br><span class="line">                <span class="keyword">if</span>(<span class="number">0</span>==j%<span class="number">2</span>) </span><br><span class="line">                    <span class="keyword">break</span> outloop; <span class="comment">//如果是双数，结束外部循环</span></span><br><span class="line">            &#125;</span><br><span class="line">             </span><br><span class="line">        &#125;</span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="1-5数组"><a href="#1-5数组" class="headerlink" title="1.5数组"></a>1.5数组</h3><h4 id="1-5-1创建数组"><a href="#1-5-1创建数组" class="headerlink" title="1.5.1创建数组"></a>1.5.1创建数组</h4><blockquote>
<p> 数组是一个<strong>固定长度</strong>的，包含了<strong>相同类型</strong>数据的 <strong>容器</strong> </p>
</blockquote>
<ul>
<li>声明数组</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// 声明一个数组</span></span><br><span class="line">        <span class="keyword">int</span>[] a;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>创建数组</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="comment">//声明一个引用</span></span><br><span class="line">        <span class="keyword">int</span>[] a;</span><br><span class="line">        <span class="comment">//创建一个长度是5的数组，并且使用引用a指向该数组</span></span><br><span class="line">        a = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">5</span>];</span><br><span class="line">         </span><br><span class="line">        <span class="keyword">int</span>[] b = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">5</span>]; <span class="comment">//声明的同时，指向一个数组</span></span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>访问数组</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span>[] a;</span><br><span class="line">        a = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">5</span>];</span><br><span class="line">         </span><br><span class="line">        a[<span class="number">0</span>]= <span class="number">1</span>;  <span class="comment">//下标0，代表数组里的第一个数</span></span><br><span class="line">        a[<span class="number">1</span>]= <span class="number">2</span>;</span><br><span class="line">        a[<span class="number">2</span>]= <span class="number">3</span>;</span><br><span class="line">        a[<span class="number">3</span>]= <span class="number">4</span>;</span><br><span class="line">        a[<span class="number">4</span>]= <span class="number">5</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>数组长度</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span>[] a;</span><br><span class="line">        a = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">5</span>];</span><br><span class="line">         </span><br><span class="line">        System.out.println(a.length); <span class="comment">//打印数组的长度</span></span><br><span class="line">         </span><br><span class="line">        a[<span class="number">4</span>]=<span class="number">100</span>; <span class="comment">//下标4，实质上是“第5个”，即最后一个</span></span><br><span class="line">        a[<span class="number">5</span>]=<span class="number">101</span>; <span class="comment">//下标5，实质上是“第6个”，超出范围 ,产生数组下标越界异常</span></span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-5-2初始化数组"><a href="#1-5-2初始化数组" class="headerlink" title="1.5.2初始化数组"></a>1.5.2初始化数组</h4><ul>
<li>分配空间与赋值分步进行</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span>[] a = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">5</span>]; <span class="comment">//分配了长度是5的数组，但是没有赋值</span></span><br><span class="line">         </span><br><span class="line">        <span class="comment">//没有赋值，那么就会使用默认值</span></span><br><span class="line">        <span class="comment">//作为int类型的数组，默认值是0</span></span><br><span class="line">        System.out.println(a[<span class="number">0</span>]);</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//进行赋值</span></span><br><span class="line">     </span><br><span class="line">        a[<span class="number">0</span>] = <span class="number">100</span>;</span><br><span class="line">        a[<span class="number">1</span>] = <span class="number">101</span>;</span><br><span class="line">        a[<span class="number">2</span>] = <span class="number">103</span>;</span><br><span class="line">        a[<span class="number">3</span>] = <span class="number">120</span>;</span><br><span class="line">        a[<span class="number">4</span>] = <span class="number">140</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>分配空间，同时赋值</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorld</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        <span class="comment">//写法一： 分配空间同时赋值</span></span><br><span class="line">        <span class="keyword">int</span>[] a = <span class="keyword">new</span> <span class="keyword">int</span>[]&#123;<span class="number">100</span>,<span class="number">102</span>,<span class="number">444</span>,<span class="number">836</span>,<span class="number">3236</span>&#125;;</span><br><span class="line"> </span><br><span class="line">        <span class="comment">//写法二： 省略了new int[],效果一样</span></span><br><span class="line">        <span class="keyword">int</span>[] b = &#123;<span class="number">100</span>,<span class="number">102</span>,<span class="number">444</span>,<span class="number">836</span>,<span class="number">3236</span>&#125;;</span><br><span class="line">         </span><br><span class="line">        <span class="comment">//写法三：同时分配空间，和指定内容</span></span><br><span class="line">        <span class="comment">//在这个例子里，长度是3，内容是5个，产生矛盾了</span></span><br><span class="line">        <span class="comment">//所以如果指定了数组的内容，就不能同时设置数组的长度</span></span><br><span class="line">        <span class="keyword">int</span>[] c = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">3</span>]&#123;<span class="number">100</span>,<span class="number">102</span>,<span class="number">444</span>,<span class="number">836</span>,<span class="number">3236</span>&#125;;</span><br><span class="line">         </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://vcomyaoyi.gitee.io/yaostaticblog/2019/11/11/java/java基础/java基础/" data-id="ck2uj38rn0007ustcp3vwtldn" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-heao/hello-world" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/yaostaticblog/2019/09/13/heao/hello-world/" class="article-date">
  <time datetime="2019-09-13T06:36:36.031Z" itemprop="datePublished">2019-09-13</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/yaostaticblog/2019/09/13/heao/hello-world/">Hello World</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>Welcome to <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="noopener">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="noopener">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="noopener">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure>

<p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="noopener">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>

<p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="noopener">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure>

<p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="noopener">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure>

<p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="noopener">Deployment</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://vcomyaoyi.gitee.io/yaostaticblog/2019/09/13/heao/hello-world/" data-id="ck2uj38qh0000ustch6no658s" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-markdown/markdown基础语法" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/yaostaticblog/2019/09/13/markdown/markdown基础语法/" class="article-date">
  <time datetime="2019-09-12T16:00:00.000Z" itemprop="datePublished">2019-09-13</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/yaostaticblog/categories/markdown/">markdown</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/yaostaticblog/2019/09/13/markdown/markdown基础语法/">markdown基础语法</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>[toc]</p>
<h1 id="一、认识markdown"><a href="#一、认识markdown" class="headerlink" title="一、认识markdown"></a>一、认识markdown</h1><p>MarDown 是一种用来写作的轻量级【标记语言】，它用简洁的语法代替排版，二不像一般我们用的文字处理软件Word或Pages有大量的排版、字体设置。它是我们专心于码字，用【标记】语法，代替常见的排版格式。</p>
<h1 id="二、文字"><a href="#二、文字" class="headerlink" title="二、文字"></a>二、文字</h1><h2 id="给文字添加颜色"><a href="#给文字添加颜色" class="headerlink" title="给文字添加颜色"></a>给文字添加颜色</h2><p>*添加红色</p>
<blockquote>
<p>效果：$\color{red}{red}$<br>写法：$\color{red}{red}$</p>
</blockquote>
<p>*添加绿色</p>
<blockquote>
<p>效果：$\color{green}{green}$<br>写法：$\color{green}{green}$</p>
</blockquote>
<p>*添加清漾青(支持更丰富的16进制颜色)</p>
<p>*为句子内的中文字符加颜色</p>
<h1 id="三、段落"><a href="#三、段落" class="headerlink" title="三、段落"></a>三、段落</h1><p>一个 MarDown段落是由一个或多个连续的文本行组成，它的前后要有一个以上的空行（快捷键：command+return）</p>
<h1 id="四、标题"><a href="#四、标题" class="headerlink" title="四、标题"></a>四、标题</h1><blockquote>
<h1 id="一级标题"><a href="#一级标题" class="headerlink" title="一级标题"></a>一级标题</h1><h2 id="二级标题"><a href="#二级标题" class="headerlink" title="二级标题"></a>二级标题</h2><h3 id="三级标题"><a href="#三级标题" class="headerlink" title="三级标题"></a>三级标题</h3><h4 id="四级标题"><a href="#四级标题" class="headerlink" title="四级标题"></a>四级标题</h4><h5 id="五级标题"><a href="#五级标题" class="headerlink" title="五级标题"></a>五级标题</h5></blockquote>
<h1 id="五、加粗、斜体、删除线"><a href="#五、加粗、斜体、删除线" class="headerlink" title="五、加粗、斜体、删除线"></a>五、加粗、斜体、删除线</h1><p><em>斜体</em> <strong>加粗</strong> <del>删除线</del></p>
<h1 id="六、列表"><a href="#六、列表" class="headerlink" title="六、列表"></a>六、列表</h1><h2 id="6-1-无序列表"><a href="#6-1-无序列表" class="headerlink" title="6.1 无序列表"></a>6.1 无序列表</h2><ul>
<li>北京</li>
<li>上海</li>
<li>南京</li>
<li>郑州</li>
</ul>
<ul>
<li>周一</li>
<li>周二</li>
<li>周三<h2 id="6-2-有序列表"><a href="#6-2-有序列表" class="headerlink" title="6.2 有序列表"></a>6.2 有序列表</h2></li>
</ul>
<ol>
<li>苹果</li>
<li>橘子</li>
<li>香蕉</li>
</ol>
<h1 id="七、引用"><a href="#七、引用" class="headerlink" title="七、引用"></a>七、引用</h1><h2 id="7-1直接在行首加-gt"><a href="#7-1直接在行首加-gt" class="headerlink" title="7.1直接在行首加&gt;"></a>7.1直接在行首加&gt;</h2><blockquote>
<p>其实作为一个程序员来说，我是不合格的<br>什么时候才能小有成就</p>
</blockquote>
<h2 id="7-2如何在行首显示-gt"><a href="#7-2如何在行首显示-gt" class="headerlink" title="7.2如何在行首显示&gt;"></a>7.2如何在行首显示&gt;</h2><blockquote>
<p>利用 <strong>\</strong> 反斜杠进行转义<br>例子：如下所示<br>&gt;</p>
</blockquote>
<h1 id="八、图片和链接"><a href="#八、图片和链接" class="headerlink" title="八、图片和链接"></a>八、图片和链接</h1><p><img src="https://upload-images.jianshu.io/upload_images/5716070-69815896d7a0968a.jpeg?imageMogr2/auto-orient/strip%7CimageView2/2/w/240" alt="妹子"></p>
<hr>
<h2 id="8-1-简书中如何设置图片大小"><a href="#8-1-简书中如何设置图片大小" class="headerlink" title="8.1 简书中如何设置图片大小"></a>8.1 简书中如何设置图片大小</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">![Snip20170622_1.png](http://upload-images.jianshu.io/upload_images/5256985-996d2f113d219267.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/240)</span><br></pre></td></tr></table></figure>

<p>1.上面的代码，是把图片直接拖拽到简书中，产生的<br>2.注意代码末尾的几个字符<strong>~/w/240</strong>。”<strong>w</strong>“是width宽度的意思，后面的240戴奥宽度的大小。只要把这个数字修改，就可以改变图片大小<br>3.比如，将<strong>~/w/240</strong>修改为~/w/1240，图像一下就变大了许多<br><img src="http://upload-images.jianshu.io/upload_images/5256985-996d2f113d219267.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/140" alt="Snip20170622_1.png"></p>
<h2 id="8-2-链接"><a href="#8-2-链接" class="headerlink" title="8.2 链接"></a>8.2 链接</h2><p>1.<a href="https://www.baidu.com" target="_blank" rel="noopener">链接描述-百度</a><br>2.<a href="https://www.baidu.com" target="_blank" rel="noopener">https://www.baidu.com</a></p>
<h1 id="九、表格"><a href="#九、表格" class="headerlink" title="九、表格"></a>九、表格</h1><table>
<thead>
<tr>
<th align="left">内容居左</th>
<th align="center">内容居中</th>
<th align="right">内容居右</th>
</tr>
</thead>
<tbody><tr>
<td align="left">A</td>
<td align="center">A</td>
<td align="right">A</td>
</tr>
<tr>
<td align="left">B</td>
<td align="center">B</td>
<td align="right">B</td>
</tr>
<tr>
<td align="left"># 十、代码引用</td>
<td align="center"></td>
<td align="right"></td>
</tr>
</tbody></table>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">public int getVerticalScrollbarWidth() &#123;</span><br><span class="line">    ScrollabilityCache cache = mScrollCache;</span><br><span class="line">    if (cache != null) &#123;</span><br><span class="line">        ScrollBarDrawable scrollBar = cache.scrollBar;</span><br><span class="line">        if (scrollBar != null) &#123;</span><br><span class="line">            int size = scrollBar.getSize(true);</span><br><span class="line">            if (size &lt;= 0) &#123;</span><br><span class="line">                size = cache.scrollBarSize;</span><br><span class="line">            &#125;</span><br><span class="line">            return size;</span><br><span class="line">        &#125;</span><br><span class="line">        return 0;</span><br><span class="line">    &#125;</span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="十一、分割线"><a href="#十一、分割线" class="headerlink" title="十一、分割线"></a>十一、分割线</h1><hr>
<hr>
<h1 id="十二、缩进"><a href="#十二、缩进" class="headerlink" title="十二、缩进"></a>十二、缩进</h1><p>一般文章需要首行缩进两个中文字符</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">一个&amp;nbsp;代表一个空格，一般2个汉字，经过测试需要7个&amp;nbsp;</span><br></pre></td></tr></table></figure>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;中文</p>
<h1 id="十三、目录"><a href="#十三、目录" class="headerlink" title="十三、目录"></a>十三、目录</h1><p>直接在文章开始添加[toc]<br><strong>注意</strong>：简书无法实现此功能，想要有目录，请参考<a href="https://www.jianshu.com/p/3f07f8f6159f" target="_blank" rel="noopener">一步步教你简书左侧自动生成目录(Markdown)</a></p>
<h1 id="十四、数学公式"><a href="#十四、数学公式" class="headerlink" title="十四、数学公式"></a>十四、数学公式</h1><p><strong>…</strong></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://vcomyaoyi.gitee.io/yaostaticblog/2019/09/13/markdown/markdown基础语法/" data-id="ck2uj38qq0001ustcvgpvn56q" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-python/pythontest" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/yaostaticblog/2019/09/13/python/pythontest/" class="article-date">
  <time datetime="2019-09-12T16:00:00.000Z" itemprop="datePublished">2019-09-13</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/yaostaticblog/categories/Python基础/">Python基础</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/yaostaticblog/2019/09/13/python/pythontest/">Python编程例程</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Python惯例"><a href="#Python惯例" class="headerlink" title="Python惯例"></a>Python惯例</h2><p>“惯例”这个词指的是“习惯的做法，常规的办法，一贯的做法”，与这个词对应的英文单词叫“idiom”。由于Python跟其他很多编程语言在语法和使用上还是有比较显著的差别，因此作为一个Python开发者如果不能掌握这些惯例，就无法写出“Pythonic”的代码。下面我们总结了一些在Python开发中的惯用的代码。</p>
<ol>
<li><p>让代码可以被导入又可以被执行。<br> if <strong>name</strong> == ‘<strong>main</strong>‘:</p>
</li>
<li><p>用西面的方式判断逻辑”真”或”假”。<br> if x:<br> if not x:</p>
</li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://vcomyaoyi.gitee.io/yaostaticblog/2019/09/13/python/pythontest/" data-id="ck2uj38qv0002ustcy5qpohgn" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/yaostaticblog/categories/Python基础/">Python基础</a></li><li class="category-list-item"><a class="category-list-link" href="/yaostaticblog/categories/java/">java</a></li><li class="category-list-item"><a class="category-list-link" href="/yaostaticblog/categories/markdown/">markdown</a></li></ul>
    </div>
  </div>


  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/yaostaticblog/archives/2019/11/">November 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/yaostaticblog/archives/2019/09/">September 2019</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/yaostaticblog/2019/11/11/java/java基础/java基础/">java基础</a>
          </li>
        
          <li>
            <a href="/yaostaticblog/2019/09/13/heao/hello-world/">Hello World</a>
          </li>
        
          <li>
            <a href="/yaostaticblog/2019/09/13/markdown/markdown基础语法/">markdown基础语法</a>
          </li>
        
          <li>
            <a href="/yaostaticblog/2019/09/13/python/pythontest/">Python编程例程</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2019 姚毅<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/yaostaticblog/" class="mobile-nav-link">Home</a>
  
    <a href="/yaostaticblog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/yaostaticblog/fancybox/jquery.fancybox.css">
  <script src="/yaostaticblog/fancybox/jquery.fancybox.pack.js"></script>


<script src="/yaostaticblog/js/script.js"></script>



  </div>
</body>
</html>